<#assign module="member"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/form.css">
</@override>
<@override name="body">

	<div class="row">

		<div class="col-xs-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					修改客户等级
			    </div>
			    <div class="panel-body">
			
					<form class="form-horizontal" id="submit_form" action="#" method="post">
		                <input type="hidden" id="id" name="id" value="${passengerGrade.id}" />
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>名称：</label>    
		                   	<div class="col-sm-3">
		                   		<input class="form-control" id="name" name="name" type="text" value="${passengerGrade.name?if_exists}" required />
		                	</div>
		                </div>
						<div class="form-group">
		                    <label for="defaultGrade" class="col-sm-3 control-label"><em>*</em>设为默认等级：</label>
		                    <div class="col-sm-3">
			                    <div class="checkbox">
			                    	<label>
									  <input type="radio" name="defaultGrade" value="true" <#if passengerGrade.defaultGrade?? && passengerGrade.defaultGrade>checked="checked"</#if>  />默认
									</label>
									<label>
									  <input type="radio" name="defaultGrade" value="false" <#if passengerGrade.defaultGrade?? && !passengerGrade.defaultGrade>checked="checked"</#if> />不默认
									</label>
								</div>
							</div>
		                </div>
		                <div class="form-group">
			                <label class="col-sm-3 control-label">所属公司:</label>
			                <label class="col-sm-3">${passengerGrade.companyName?if_exists}</label>
						 </div>
						 <div class="form-group">
                            <label class="col-sm-3 control-label">并行订单量：</label>
                            <div class="col-sm-3">
                                <input class="form-control" id="parallelOrderNumber" name="parallelOrderNumber" type="number" value="${passengerGrade.parallelOrderNumber?if_exists}"/>
                            </div>
                        </div>
                        <p style="margin-left: 350px;color: red;">
                            订单未结束可继续下单的数量，不设置表示不限制
                        </p>
                        <p style="margin-left: 350px;color: red;">
                            最小为1设置数字不能小于“一次性下单最大数量”的设置
                        </p><br>
                        
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">一次性下单最大数量：</label>    
		                   	<div class="col-sm-3">
		                   		<input class="form-control" id="limitAmounts" name="limitAmounts" max="10" value="${passengerGrade.limitAmounts?if_exists}" type="number" />
		                	</div>
		                	<label class="control-label"><em>不填写则不限制</em></label>
		                </div>
		                
		                <@daijia>
		                <h4>代驾收费标准（不选择则订单公司上代驾收费为默认）</h4>
		                <hr/>
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">代驾收费标准：</label>    
		                   	<div class="col-sm-3">
		                   		<select class="form-control" id="daijiaAreaId" name="daijiaAreaId">
			                    	<option value="">--请选择--</option>
			                    	<#list arealist as area>
		                    			<option value="${area.id}" <#if passengerGrade.daijiaAreaId?? && passengerGrade.daijiaAreaId==area.id>selected="selected"</#if>>${area.name?if_exists}</option>
									</#list>
			                    </select>
		                	</div>
		                </div>
		                </@daijia>
		                
		                <@zhuan>
			               <div class="form-group">
			                   	<div class="col-sm-2">
			                   	</div>
			                   	<div class="col-sm-10">
				                	<ul class="nav nav-tabs" id="carTypeList" style="cursor:default;">
				                		<#if carTypes ??>
					                		<#list carTypes as c>
							            		<li><a href="#zhuanTab" data-toggle='tab'>${c.typeName?if_exists}</a></li>
							            	</#list>
						            	</#if>
						            </ul>
		                		 	<label class="control-label"><em>专车收费标准（不选择则使用专车类型上的收费标准）</em></label> 
						        </div>
					       </div>
					       <div id="carType_div">
					       </div>
	                    </@zhuan>
	                    
<@gasstation>	                    
<h4>加油站折扣设置（默认为0，表示不享受折扣）</h4> 
<hr/>	                    
<div class="form-group" style="margin-left:18%;">
            <table class="table table-condensed table-striped" style="width:1080px;">
	            <tbody>
	            	<tr>
						<th style='width:10%;text-align:center;'>服务号</th>
						<th style='width:15%;text-align:center;'>
							<div class="show-price">
								享受折扣&nbsp;&nbsp;
								<button type="button" class="btn btn-default btn-xs edit-discount-button">
								  <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
								</button>
							</div>
							<div class="input-group input-group-sm edit-price" style="display:none;">
						    	<input type="text" class="form-control edit-discount-input" value="" placeholder="修改全部折扣">
						    	<span class="input-group-btn">
						        	<button class="btn btn-primary save-discount" type="button" data-gsId="">同步</button>
					    		</span>
						    </div>
						</th>
						<th style='text-align:center;'>名称</th>
						<th style='text-align:center;'>地址</th>
						<th style='text-align:center;'>品牌</th>
						<th style='text-align:center;'>联系人</th>
						<th style='text-align:center;'>联系电话</th>
						<th style='text-align:center;'>座机</th>
					</tr>
					<#if page?? >
					  	<#list page.content as data>
					  	    <#assign  flag = 0 >
					  	    <#assign  discount = 0 >
						  	<#list list as discounts>
							  <#if data.id==discounts.gsId>
							    <#assign  flag = 1 >
					  	    	<#assign  discount = discounts.discount >
							  </#if>
							</#list>
							
							<tr>
								<td style="text-align:center;">${data.serviceNo?if_exists}</td>
								<td style="text-align:center;" class="discounts">
									<div class="show-price">
										<span class="show-price-span">${discount}</span>&nbsp;&nbsp;
										<button type="button" class="btn btn-default btn-xs edit-price-button">
										  <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
										</button>
									</div>
									<div class="input-group input-group-sm edit-price" style="display:none;">
								    	<input type="text" class="form-control edit-price-input" value="${discount}" placeholder="0表示不打折">
								    	<span class="input-group-btn">
								        	<button class="btn btn-primary save-price" type="button" data-gsId="${data.id}">保存</button>
							    		</span>
								    </div>
								</td>
								<td style="text-align:center;">${data.name?if_exists}</td>
								<td style="text-align:center;">${data.address?if_exists}</td>
								<td style="text-align:center;">${data.brand?if_exists}</td>
								<td style="text-align:center;">${data.contacts?if_exists}</td>
								<td style="text-align:center;">${data.contactsPhone?if_exists}</td>
								<td style="text-align:center;">${data.telephone?if_exists}</td>
							
							</tr>
						</#list>
					</#if>
	            </tbody>
		</table>
</div>
</@gasstation>
	                    
	                    
	                    
		             
		                <div class="form-group">
		                	<div class="col-sm-3">
		                	</div>
		                	<div class="col-sm-3">
				                <input id="submit_button" type="button" class="btn btn-primary" value="保存">
				                <input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/member/gradelist';" value="返回">
			            	</div>
			            </div>
		            </form>
				</div>
			</div>
						        	
		</div>
		
	</div>
	

</@override>
<@override name="footer">
<script type="text/javascript">
	window.daijia.ctx = '${ctx}';
	window.companyId = '${passengerGrade.companyId?if_exists}';
	window.gradeId = '${passengerGrade.id?if_exists}';
	window.haszhuanche=false;
	<@zhuan>
	     haszhuanche=true;
	</@zhuan>
	//点击修改价格
	$(document).on("click",".edit-price-button",function(){
		$(this).parent().hide();
		$(this).parent().parent().find(".edit-price").show();
	});
	$(document).on("click",".edit-discount-button",function(){
		$(this).parent().hide();
		$(this).parent().parent().find(".edit-price").show();
	});
	
	//保存修改价格
	$(document).on("click",".save-price",function(){
		var price_yz=/^((0\.[1-9]?)|([1-9](\.\d)?)|0)$/;
		var editd_price=$(this).parent().parent().find(".edit-price-input").val();
		if(!price_yz.test(editd_price)){
			alert("请输入正确的折扣（0-9.9）。");
			return false;
		}
		
		var this_button=$(this);
		this_button.attr("disabled",true);
		$.post(ctx+"/gasstation/saveGasDiscount",{"gsId":this_button.attr("data-gsId"),"discount":editd_price,"passengerGradeId":${passengerGrade.id}},function(result){
			if(result.code==0){
				this_button.attr("disabled",false);
				this_button.parent().parent().hide();
				this_button.parent().parent().parent().find(".show-price .show-price-span").html(editd_price);
				this_button.parent().parent().parent().find(".show-price").show();
			}
			else{
				$.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
				this_button.attr("disabled",false);
			}
		});
	});
	
	//同步
	$(document).on("click",".save-discount",function(){
		var price_yz=/^((0\.[1-9]?)|([1-9](\.\d)?)|0)$/;
		var edit_discount=$(this).parent().parent().find(".edit-discount-input").val();
		if(!price_yz.test(edit_discount)){
			alert("请输入正确的折扣（0-9.9）。");
			return false;
		}
		
		$(".edit-discount-button").attr("disabled",true);
		$.post(ctx+"/gasstation/saveGasDiscountAll",{"discount":edit_discount,"passengerGradeId":${passengerGrade.id}},function(result){
			if(result.code==0){
				$(".edit-discount-button").attr("disabled",false);
				$(".show-price-span").html(edit_discount);
				$(".edit-price-input").html(edit_discount);
				$(".edit-price-input").val(edit_discount);
				$(".edit-price").hide();
				$(".show-price").show();
				
			}
			else{
				$.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
				this_button.attr("disabled",false);
			}
		});
	});
	
	
</script>
<script src="${ctx}/assets/js/member/editgrade.js"></script>
</@override>
<@extends name="../layout.ftl"/>